<template>
  <div class="app-container">
    <!--用户数据-->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="房间">
        <el-input v-model="queryParams.premisesAddress" placeholder="请输入房间" clearable style="width: 240px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="地区" prop="region">
        <el-cascader ref="areaPicker" v-model="queryParams.region" :props="areaProps" :show-all-levels="true"
          @change="handleChangeArea" clearable></el-cascader>
      </el-form-item>
      <el-form-item label="流程配置">
        <el-select v-model="queryParams.cleaningProcessState" placeholder="请选择" clearable>
          <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
      </el-col>
      <!-- <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" width="50" align="center" /> -->
      <el-table-column label="房间" align="center" key="premisesAddress" prop="premisesAddress"
        :show-overflow-tooltip="true" />
      <el-table-column label="地区" align="center" key="district" prop="district" />
      <el-table-column label="流程配置" align="center" prop="cleaningProcessState">
        <template slot-scope="scope">
          <span>{{ cleaningProcessState(scope.row.cleaningProcessState) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleProcess(scope.row)"
            v-hasPermi="['enterprise:cleaningProcess:tree']">设置流程</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <settingProcess v-model="open" :houseId="houseId" @success="getList" />
  </div>
</template>

<script>
import { listArea } from "@/api/system/config";
import { listUserBusiness, delUserBusiness } from "@/api/enterprise/user";

import { listCleaningProcess } from "@/api/houseCleaning/process";
import settingProcess from './settingProcess/index.vue'

export default {
  name: "Index",
  dicts: ['sys_normal_disable', 'sys_user_sex'],
  components: { settingProcess },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      list: null,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 表单参数
      form: {},
      //房屋id
      houseId: undefined,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        provinceId: undefined,
        cityId: undefined,
        streetId: undefined,
        premisesAddress: undefined,
        cleaningProcessState: undefined,
      },
      // 列信息
      columns: [
        { key: 0, label: `用户编号`, visible: true },
        { key: 1, label: `用户名称`, visible: true },
        { key: 2, label: `用户昵称`, visible: true },
        { key: 3, label: `部门`, visible: true },
        { key: 4, label: `手机号码`, visible: true },
        { key: 5, label: `状态`, visible: true },
        { key: 6, label: `创建时间`, visible: true }
      ],
      //配置内容
      options: [
        {
          label: '已设置',
          value: '0'
        },
        {
          label: '未设置',
          value: '1'
        }
      ],
      areaProps: {
        lazy: true,
        // emitPath: false,
        lazyLoad(node, resolve) {
          const { level } = node;
          if (level < 4) {
            listArea({ level: node.level + 1, parentId: node.value }).then(
              (res) => {
                const areas = res.data.map((value, i) => ({
                  value: value.id,
                  label: value.name,
                  leaf: level >= 3,
                }));
                resolve(areas);
              }
            );
          } else {
            resolve([]);
          }
        },
        checkStrictly: true,
      },
    };
  },
  computed: {
    cleaningProcessState() {
      return (value) => {
        let obj = this.options.find(item => item.value == value)
        return obj.label
      }
    }
  },
  watch: {
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      listCleaningProcess(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.list = response.rows;
        this.total = response.total;
        this.loading = false;
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        danhao: undefined,
        fangjian: undefined,
        fenlei: undefined,
        status: undefined,
        yanfangyuan: undefined
      },
        this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.userId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    handleChangeArea(val) {
      if (val.length) {
        const checkedNode = this.$refs["areaPicker"].panel.getNodeByValue(val);
        const ids = checkedNode.path;
        this.queryParams.provinceId = ids[0];
        this.queryParams.cityId = ids[1];
        this.queryParams.districtId = ids[2];
        this.queryParams.streetId = ids[3];
      }else{
        this.queryParams.provinceId = undefined;
        this.queryParams.cityId = undefined;
        this.queryParams.districtId = undefined;
        this.queryParams.streetId = undefined;
      }

    },
    //设置流程
    handleProcess(row) {
      this.houseId = row.houseId
      this.open = true
    }
  }
};
</script>

<style lang="scss" scoped></style>
